<?php
// 如果当前作品已发布 即已付费，进入此编辑器进行修改 则直接保存
if (isset ($workMsg) && $workMsg->State == 1) {
    $rel_script = "work_save(1)";
} else {
    $rel_script = "show_pay_actions(2,1)";
    ?>
    <div id="top_fade_out_div" class="app-editor-fade-tittle app-main-color">
        付费发布，2元一篇
    </div>
<?php } ?>

<div id="work_edit_div" class="app-toolbar-content">
    <?php
    $editor_type = 1;
    require("{$CfgPara->root}/view/tittle_editor_bar.app.v.php");
    ?>
    <div class="editor-project editor_text">
        <input
                id="work_value_releasedt" onchange="$('#work_value_releasedt_dis').val($(this).val());"
                type="text" style="display: none;"
                value="<?php if (isset($workMsg)) echo substr($workMsg->ReleaseDt, 0, 10); ?>"/>
        <ul id="editor_text_list" class="am-list" style="margin-top:15px">
            <li id="work_edit_name" class="app-work-content-li">
                <input placeholder="请输入作品标题"
                       style="border:none; width:98%; font-weight: bold"
                       id="work_value_tittle"
                       value="<?php if (isset($workMsg)) echo $workMsg->Name; ?>"/>
            </li>
            <li id="work_edit_introd" class="app-work-content-li">
                <div data-am-modal="{target: '#popup_introd_edit'}">
                    <input type="text" readonly style="border: none;width: 40%" value="作品介绍"/>
                    <input placeholder="请输入作品介绍"
                           id="work_value_introd" class="app-gray2-color app-editor-item" readonly
                           value="<?php if (isset($workMsg)) echo $workMsg->Introd; ?>"/>
                </div>
            </li>
            <li id="work_edit_type" class="app-work-content-li">
                <div data-am-modal="{target: '#popup_type_edit'}">
                    <input type="text" readonly style="border: none;width: 40%" value="类型"/>
                    <input placeholder="请选择作品类型"
                           class="app-gray2-color app-editor-item" readonly
                           id="work_value_type"
                           value="<?php
                           if (isset($workMsg)) {
                               if ($workMsg->Type == 2)
                                   echo '自制';
                               else
                                   echo '定制';
                           }
                           ?>"/>
                </div>
            </li>
            <li id="work_edit_stype" class="app-work-content-li am-panel">
                <div data-am-modal="{target: '#popup_stype_edit'}">
                    <input type="text" readonly style="border: none;width: 40%" value="鞋款"/>
                    <input placeholder="请输入作品鞋款"
                           id="work_value_stype" class="app-gray2-color app-editor-item" readonly
                           value="<?php if (isset($workMsg)) echo $workMsg->SType; ?>"/>
                </div>
            </li>
            <li id="work_edit_tags" class="app-work-content-li am-panel">
                <div data-am-modal="{target: '#popup_tags_edit'}">
                    <input type="text" readonly style="border: none;width: 40%" value="标签"/>
                    <input placeholder="请输入标签"
                           id="work_value_tags" class="app-gray2-color app-editor-item" readonly
                           value="<?php if (isset($workMsg)) echo $workMsg->Tags; ?>"/>
                </div>
            </li>

            <li id="work_edit_releasedt" class="app-work-content-li am-panel">
                <div onclick="$('#work_value_releasedt').click();">
                    <input type="text" readonly style="border: none;width: 40%" value="创作时间(选填)"/>
                    <input placeholder="请输入创作时间"
                           id="work_value_releasedt_dis"
                           class="app-gray2-color app-editor-item" readonly
                           value="<?php if (isset($workMsg)) echo substr($workMsg->ReleaseDt, 0, 10); ?>"/>
                </div>
            </li>
        </ul>
    </div>

    <div class="editor-project editor_image_list" style="display: none">
        <div id="img_list_demo" style="padding:5px 0 0 16px;">
            <?php
            $imgCount = 0;
            if (isset($imgList)) {
                foreach ($imgList as $imgName) {
                    if (isset($imgName) && $imgName != '') {
                        //data-issave表示是否是已保存在正式文件夹中的图片
                        echo "<img data-issave='1' onclick='img_sele_change(this)' class='app-img-preview' src='{$imgName}' />";
                        $imgCount++;
                    }
                }
            }
            echo '<a id="editor_img_plus" onclick="img_add_trig()"><img src="/img/editor_plus.png" class="app-img-preview"></a>'
            ?>
        </div>
        <div id="img_edit_btn" style="height:38px;padding:5px;">
            <span class="am-fr" style="padding-top:3px">
                <span id="img_count"><?= $imgCount ?></span>/<span id="img_max_count">9</span>
            </span>
        </div>
    </div>

    <div class="editor-project editor_image_cut" style="display: none">
        <div style="margin-top:10px; padding:0;">
            <div id="div_need_cut" style="overflow: hidden;background-color:black; border:none">
                <img id="img_need_cut" style="position:relative; top:0; left:0; width:100%;"
                     src=""/>
            </div>
            <div style="text-align:center;margin-top:20px">
                <img src="/img/editor_cut.png" alt="">
            </div>
            <div style="display:none">
                <canvas id="img_canvas" width="1024" height="768"></canvas>
            </div>
        </div>
    </div>

    <div class="editor-project editor_image_dele" style="display: none">
        <img id="editor_image_need_dele" src="" alt="" style="width:100%">
    </div>
</div>
<div id="work_edit_toolbar" class="am-btn-group" style="width:100%">
    <a style="width:100%; height:45px;padding-top:10px;"
       class="am-btn app-main-backcolor editor-btn editor_btn_text"
       role="button"
       onclick="img_add_trig(<?= $editor_type ?>);">
        <span class="am-text-sm">上传作品图片</span>
    </a>
    <div style="width:100%; height:45px; border-top:1px solid; padding:10px; text-align:center; display:none"
         class="editor-btn editor_btn_image_cut app-gray-color">
        <a class="am-icon am-icon-angle-left am-icon-fw am-fl" onclick="editor_show('text')"></a>
        <span id="bar_tittle">裁剪</span>
        <a class="am-icon am-icon-angle-right am-icon-fw am-fr" onclick="imgCut.Upload();"></a>
    </div>
    <a onclick="<?= $rel_script ?>" style="width:100%; height:45px;padding-top:10px; display:none"
       class="am-btn app-main-backcolor editor-btn editor_btn_image_list" role="button">
        <span class="am-text-sm">发布</span>
    </a>
</div>
<div style="display:none">
    <input id="img_new_file" type="file" onchange="img_show_change(this)"/>
    <input id="parent_type" value="1"/>
    <input id="parent_state" value="<?php if (isset($workMsg)) echo $workMsg->State; else echo '0'; ?>"/>
    <input id="parent_id" type="text" value="<?php if (isset($workMsg)) echo $workMsg->Id; else echo '0'; ?>"/>
</div>

<div class="am-popup" id="popup_introd_edit">
    <div class="am-popup-inner" style="background-color:#F8F8F8">
        <div class="app-main-backcolor am-popup-hd">
            <h4 style="color:#FFF" class="am-popup-title">作品简介</h4>
        </div>
        <div class="am-popup-bd">
            <div class="am-form">
                <div class="am-form-group">
                    <textarea placeholder="请输入作品简介（作品灵感、创作故事、客户要求，用简介有魅力的文字分享给大家吧）" id="work_edit_content_introd"
                              rows="5"
                              style="width: 100%"><?php if (isset($workMsg)) echo $workMsg->Introd; ?></textarea>
                    <button style="margin-top:10px" data-am-modal-close type="button" class="am-btn am-btn-sm am-fr"
                            onclick="reset_editor_value('introd')">取消
                    </button>
                    <button style="margin-top:10px" data-am-modal-close type="button"
                            class="am-btn app-main-backcolor am-btn-sm am-fr" onclick="set_editor_value('introd')">确定
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="am-popup" id="popup_stype_edit">
    <div class="am-popup-inner" style="background-color:#F8F8F8">
        <div class="app-main-backcolor am-popup-hd">
            <h4 style="color:#FFF" class="am-popup-title">作品鞋款</h4>
        </div>
        <div class="am-popup-bd">
            <div class="am-form">
                <div class="am-form-group">
                    <textarea placeholder="请输入作品鞋款（要求输入的鞋款名单词全用大写，也可在下列的热门鞋款中选择。请查询鞋款的正确全名）"
                              id="work_edit_content_stype" rows="4"
                              style="width: 100%"><?php if (isset($workMsg)) echo $workMsg->SType; ?></textarea>
                    <button style="margin-top:10px" data-am-modal-close type="button" class="am-btn am-btn-sm am-fr"
                            onclick="reset_editor_value('stype')">取消
                    </button>
                    <button style="margin-top:10px" data-am-modal-close type="button"
                            class="am-btn am-btn-primary am-btn-sm am-fr" onclick="set_editor_value('stype')">确定
                    </button>
                </div>
                <table class="am-table">
                    <thead>
                    <tr>
                        <th>热门鞋款</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                    //输出热门鞋款列表
                    foreach ($hot_shoe_style as $hot) {
                        echo "<tr><td onclick='hot_shoe_style_sele(this)'>{$hot}</td></tr>";
                    }
                    ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<div class="am-popup" id="popup_tags_edit">
    <div class="am-popup-inner" style="background-color:#F8F8F8">
        <div class="app-main-backcolor am-popup-hd">
            <h4 style="color:#FFF" class="am-popup-title">作品标签</h4>
        </div>
        <div class="am-popup-bd">
            <div class="am-form">
                <div class="am-form-group">
                    <textarea
                            placeholder="请输入作品标签（多个标签用空格分隔。标签填写作品标题和鞋款名以外的关键词，更有利于搜索和系统内推荐。例如：作品名里有乔丹6，鞋款名AIR JORDAN 6，这时标签里可以填写AJ6。）"
                            id="work_edit_content_tags"
                            rows="6"
                            style="width: 100%"><?php if (isset($workMsg)) echo $workMsg->Tags; ?></textarea>
                    <button style="margin-top:10px" data-am-modal-close type="button" class="am-btn am-btn-sm am-fr"
                            onclick="reset_editor_value('tags')">取消
                    </button>
                    <button style="margin-top:10px" data-am-modal-close type="button"
                            class="am-btn am-btn-primary am-btn-sm am-fr" onclick="set_editor_value('tags')">确定
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="am-popup" id="popup_type_edit">
    <div class="am-popup-inner" style="background-color:#F8F8F8">
        <div class="app-main-backcolor am-popup-hd">
            <h4 style="color:#FFF" class="am-popup-title">作品类型</h4>
        </div>
        <div class="am-popup-bd">
            <div class="am-form">
                <div class="am-form-group">
                    <label class="am-radio-inline">
                        <input type="radio"
                               value="1"
                               name="work_edit_content_type"
                            <?php if (!isset($workMsg->Type) || $workMsg->Type == 0 || $workMsg->Type == 1) echo 'checked'; ?> >
                        定制 （为客户制作的）
                    </label>
                    <br/>
                    <label class="am-radio-inline">
                        <input type="radio"
                               value="2"
                               name="work_edit_content_type"
                            <?php if (isset($workMsg->Type) && $workMsg->Type == 2) echo 'checked'; ?>> 自制 （做给自己的）
                    </label>
                    <button style="margin-top:30px" data-am-modal-close type="button" class="am-btn am-btn-sm am-fr"
                            onclick="reset_editor_value('type')">取消
                    </button>
                    <button style="margin-top:30px" data-am-modal-close type="button"
                            class="am-btn am-btn-primary am-btn-sm am-fr" onclick="set_editor_value('type')">确定
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    /*
     $('#work_value_releasedt').datetimepicker({
     language:  'zh-CN',
     format: 'yyyy-mm-dd hh:ii',
     autoclose: true,
     pickerPosition: 'top-left'
     });
     */
    $('#work_value_releasedt').datepicker({format: 'yyyy-mm-dd'});
    if (imgCut == null) {
        imgCut = new CImgCut();
    }
    img_show_upload_ini();
    setTimeout('toolbar_ini("work_edit_div", "work_edit_toolbar");', 20);
    // 头部的付费提示 3秒后淡出消失
    setTimeout("$('#top_fade_out_div').fadeOut('slow')", 3000);
</script>